import Vuex from "vuex"
import Vue from "vue"
import axios from "axios"
import { nanoid } from "nanoid"
Vue.use(Vuex)
let state = {
    n: 5
}
let mutations = {
    ADD(staten,count=1) {
        state.n+=count
    },
    SUB(state) {
        state.n--
    }
}
let actions = {
    add({ commit },data) {
        console.log(data );
        commit("ADD")
    },
    sub({ commit }) {
        commit("SUB")
    },
    eventAdd({ commit, state }) {
        if (state.n % 2 === 0) {
            commit("ADD")
        }
    },
    AsyncAdd({ commit }) {
        setTimeout(() => {
            commit("ADD")
        }, 2000);

    },
}
let getters = {
    count(state) {
        return state.n * 20
    }

}
export default new Vuex.Store({
    state,
    mutations,
    actions,
    getters,
    modules:{},
})